/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package opera.InterfaceGrafica.PaineisCriarOuAbrirJogo;

import java.io.File;
import javax.swing.JButton;
import javax.swing.JComboBox;
import opera.InterfaceGrafica.MoldePaineis;

/**
 *
 * @author Luciano
 */
public class PnlAbrirJogo extends MoldePaineis {

    /**
     * Getters
     */
    public JButton getBtnCancelar(){
        return btnCancelar;
    }
    public JButton getBtnAbrir(){
        return btnAbrir;
    }
    public JComboBox getCmbSelecionarJogo(){
        return cmbSelecionarJogo;
    }
    
    
    /**
     * Creates new form PnlAbrirJogo
     */
    public PnlAbrirJogo() {
        initComponents();
        carregarJogos();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        lblSelecionarJogo = new javax.swing.JLabel();
        cmbSelecionarJogo = new javax.swing.JComboBox();
        btnCancelar = new javax.swing.JButton();
        btnAbrir = new javax.swing.JButton();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Abrir Jogo"));

        lblSelecionarJogo.setText("Selecione o Jogo:");

        cmbSelecionarJogo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbSelecionarJogo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbSelecionarJogoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblSelecionarJogo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(cmbSelecionarJogo, 0, 244, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblSelecionarJogo)
                    .addComponent(cmbSelecionarJogo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btnCancelar.setText("Cancelar");

        btnAbrir.setText("Abrir");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(btnAbrir)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnCancelar))
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancelar)
                    .addComponent(btnAbrir)))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void cmbSelecionarJogoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbSelecionarJogoActionPerformed
        // TODO add your handling code here:
        //carregarJogos();
    }//GEN-LAST:event_cmbSelecionarJogoActionPerformed

    
    private void carregarJogos(){
        cmbSelecionarJogo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { ""}));
        File diretorio = new File("C:\\Opera\\Jogos");
        boolean statusDiretorio = true;
        if(!diretorio.exists()){
            statusDiretorio = diretorio.mkdir();
        }
        String diretorios[] = diretorio.list();
        for(int i = 0; i < diretorios.length; i++){
            //System.out.println(diretorios[i]);
            cmbSelecionarJogo.addItem(diretorios[i]);
        }
    }
    
    @Override
    public void atualizarJComboBox(){
        carregarJogos();
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAbrir;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JComboBox cmbSelecionarJogo;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lblSelecionarJogo;
    // End of variables declaration//GEN-END:variables

}
